// 配置路由
import Vue from 'vue';
import VueRouter from 'vue-router';

// 使用插件
Vue.use(VueRouter);

// 引入路由组件
import Home from '../pages/Home'
import Search from '../pages/Search'
import Login from '../pages/Login'
import Register from '../pages/Register'
import Detail from '../pages/Detail'
import AddCartSuccess from '../pages/AddCartSuccess'
import ShopCart from '../pages/ShopCart'

export default new VueRouter({
    // 配置路由
    routes: [{
            path: "/home",
            component: Home,
            meta: {
                show: true
            }
        },
        {
            // 带上?就params参数可以带也可以不带
            path: "/search/:keyword?",
            component: Search,
            meta: {
                show: true
            },
            name: "search",
            props: true
        },
        {
            path: "/login",
            component: Login,
            meta: {
                show: false
            }
        },
        {
            path: "/register",
            component: Register,
            meta: {
                show: false
            }
        },
        {
            // 商品详情
            // 当点击商品的图片的时候，跳转到详情页面，在路由的时候需要带上产品的ID给详情页面
            path: "/detail/:skuId",
            component: Detail,
            meta: {
                show: true
            }
        },
        {
            name: 'addcartsuccess',
            path: "/addcartsuccess",
            component: AddCartSuccess,
            meta: {
                show: true
            }
        },
        {
            name: 'shopcart',
            path: "/shopcart",
            component: ShopCart,
            meta: {
                show: true
            }
        },
        {
            path: "*",
            redirect: "/home"
        }
    ],
    scrollBehavior(to, from, savedPosition) {
        // 始终滚动到顶部
        return { y: 0 }
    },
})